#pragma once
#include"RBTree.h"
namespace celia
{
	template<class K, class V>
	class MyMap
	{
		struct KeyOfV
		{
			const K& operator()(const pair<K, V>& p)
			{
				return p.first;
			}
		};
	public:
		typedef typename RBTree<K, pair<const K, V>, KeyOfV>::Iterator iterator;
		typedef typename RBTree<K, pair<const K, V>, KeyOfV>::const_Iterator const_iterator;

		iterator begin()
		{
			return _t.begin();
		}
		iterator end()
		{
			return _t.end();
		}
		const_iterator begin() const
		{
			return _t.begin();
		}
		const_iterator end() const
		{
			return _t.end();
		}
		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = Insert({ key, V() });
			return ret.first->second;
		}
		pair<iterator, bool> Insert(const pair<const K, V>& p)
		{
			return _t.Insert(p);
		}

	private:
		RBTree<K, pair<const K, V>, KeyOfV> _t;
	};
}